package com.hot100.easy;

/**
 * @ClassName Demo16
 * @Description 反转二叉树
 * @Author zt
 * @Date 16:22 2022/6/11
 * @Version 1.0
 **/
public class Demo16 {
    public static void main(String[] args) {

    }
    public TreeNode invertTree(TreeNode root) {
        if(root==null){
            return null;
        }
        if(root.left==null&&root.right==null){
            return root;
        }else {
            TreeNode temp=root.right;
            root.right=root.left;
            root.left=temp;
            invertTree(root.right);
            invertTree(root.left);
            return root;
        }


    }



    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}